package com.cbn.ibcp.jishiting.statistic.service.impl;

import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.cbn.ibcp.common.annotation.DataSource;
import com.cbn.ibcp.common.enums.DataSourceType;
import com.cbn.ibcp.jishiting.statistic.domain.OrgInjectDataStatistic;
import com.cbn.ibcp.jishiting.statistic.domain.OssInjectDataStatistic;
import com.cbn.ibcp.jishiting.statistic.enums.DeleteStatusEnums;
import com.cbn.ibcp.jishiting.statistic.mapper.OrgInjectDataStatisticMapper;
import com.cbn.ibcp.jishiting.statistic.mapper.OssInjectDataStatisticMapper;
import com.cbn.ibcp.jishiting.statistic.service.IOrgInjectDataStatisticService;
import com.cbn.ibcp.jishiting.statistic.service.IOssInjectDataStatisticService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Objects;

@Service
@Slf4j
@RequiredArgsConstructor
public class OrgInjectDataStatisticServiceImpl implements IOrgInjectDataStatisticService {

    private final OrgInjectDataStatisticMapper orgInjectDataStatisticMapper;

    @DataSource(DataSourceType.jishiting_statistic)
    @Override
    public List<OrgInjectDataStatistic> getListByDay(String dayStr) {
        if (StrUtil.isBlank(dayStr)) {
            return null;
        }
        LambdaQueryWrapper<OrgInjectDataStatistic> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.likeRight(OrgInjectDataStatistic::getDateId, dayStr);
        queryWrapper.eq(OrgInjectDataStatistic::getDeleteStatus, DeleteStatusEnums.DELETED_STATUS_0.getCode());
        return orgInjectDataStatisticMapper.selectList(queryWrapper);
    }


    @DataSource(DataSourceType.jishiting_statistic)
    @Override
    public int insert(OrgInjectDataStatistic orgInjectDataStatistic) {
        if (Objects.isNull(orgInjectDataStatistic)) {
            return 0;
        }
        return orgInjectDataStatisticMapper.insert(orgInjectDataStatistic);

    }
}
